import socket
import ssl


def client_call(url, charset=None, headers=None):
    # create socket object
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    if headers is None:
        headers = 'User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'

    # if the url is http type
    if 'http://' in url:
        url = url.replace('http://', '')
        port = 80

    # if the url is https type
    if 'https://' in url:
        client = ssl.wrap_socket(client)
        url = url.replace('https://', '')
        port = 443

    url = url if '/' in url else url + '/'
    url_split = url.split('/', 1)

    # connect to the server
    client.connect((url_split[0], port))

    # send the report to process
    request = 'GET /{1} HTTP/1.1\r\nHost: {0}\r\n{2}\r\nConnection: close\r\n\r\n'.format(url_split[0], url_split[1], headers)

    client.send(request.encode())
    response = client.recv()

    return response


host = 'https://www.baidu.com'
res = client_call(host)
print(res)
